package data;

import java.sql.*;

public class CellSample extends DataElement
{
    public int grid_id;
    public int gridsample_id;
    public java.util.Date time;
    public double coord_theta;
    public double coord_phi;
    public double coord_radius;
    public double coord_latitude;
    public double coord_longitude;
    public double value;
	
    public CellSample( DataFactory factory )
    {
	super( factory );
    }
    
    protected String valuesString()
    {
	String convertedTime = "'" + (new java.sql.Timestamp( time.getTime() )).toString() + "'";
	return "" + grid_id + ", " + 
		gridsample_id + ", " +
	    convertedTime + ", " +
	    coord_theta + ", " +
	    coord_phi + ", " +
	    coord_radius + ", " +
	    coord_latitude + ", " + 
	    coord_longitude + ", " +
	    value;
    }
    
    protected void _loadFrom( ResultSet rs ) throws SQLException
    {
	grid_id = rs.getInt( "grid_id" );
	gridsample_id = rs.getInt("gridsample_id");
	time = new java.util.Date( rs.getTimestamp( "time" ).getTime() );
	coord_theta = rs.getDouble( "coord_theta" );
	coord_phi = rs.getDouble( "coord_phi" );
	coord_radius = rs.getDouble( "coord_radius" );
	coord_latitude = rs.getDouble( "coord_latitude" );
	coord_longitude = rs.getDouble( "coord_longitude" );
	value = rs.getDouble( "value" );
    }
    
    protected String _insert()
    {
	return "(grid_id, gridsample_id, time, coord_theta, coord_phi, coord_radius, coord_latitude, coord_longitude, value) values (" + valuesString() + ")";
    }
    
    protected String _update()
    {
	String convertedTime = "'" + (new java.sql.Timestamp( time.getTime() )).toString() + "'";
	return "grid_id=" + grid_id +
		"gridsample_id=" + gridsample_id + 
	    ", time=" + convertedTime + 
	    ", coord_theta=" + coord_theta +
	    ", coord_phi=" + coord_phi +
	    ", coord_radius=" + coord_radius +
	    ", coord_latitude=" + coord_latitude +
	    ", coord_longitude=" + coord_longitude +
	    ", value=" + value;
    }


    /*
    public Cell getCell()
    {
	return getFactory().getDatabase().getCellFactory().lookup( cell_id );
    }
    */
}
